package backtrackStudy;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class WangYi {

    private static int ans = 0;

    public static void main(String[] args) throws Exception{
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        String s = buf.readLine();
        String[] ss = s.split(" ");
        String[] arr = ss[0].split(",");
        int target = Integer.parseInt(ss[1]);
        int[] nums = new int[arr.length];
        for (int i = 0; i < arr.length; i++){
            nums[i] = Integer.parseInt(arr[i]);
        }
        backtrace(nums, 0, target);
        System.out.println(ans);
    }
    public static void backtrace(int[] nums, int index, int target){
        if (index == nums.length){
            if (target == 0){
                ans++;
            }
            return;
        }

        backtrace(nums, index + 1, target + nums[index]);

        backtrace(nums, index + 1, target - nums[index]);

    }
}
